namespace AceSoft.RetailPlus.MasterFiles._ContactGroup
{
	using System;
	using System.Data;
	using System.Drawing;
	using System.Web;
	using System.Web.UI.WebControls;
	using System.Web.UI.HtmlControls;
	using AceSoft.RetailPlus.Data;
	
	public partial  class __Insert : System.Web.UI.UserControl
	{

		#region Web Form Methods

		protected void Page_Load(object sender, System.EventArgs e)
		{
			if (!IsPostBack)
			{
				if (Visible)
				{
					lblReferrer.Text = Request.UrlReferrer == null ? Constants.ROOT_DIRECTORY : Request.UrlReferrer.ToString();
					LoadOptions();			
				}
			}
		}
		
		#endregion

		#region Web Form Designer generated code

		override protected void OnInit(EventArgs e)
		{
			InitializeComponent();
			base.OnInit(e);
		}
		private void InitializeComponent()
		{
		}

		#endregion

		#region Web Control Methods

        protected void imgSave_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			SaveRecord();
			string stParam = "?task=" + Common.Encrypt("add",Session.SessionID);
			Response.Redirect("Default.aspx" + stParam);	
		}
		protected void cmdSave_Click(object sender, System.EventArgs e)
		{
			SaveRecord();
			string stParam = "?task=" + Common.Encrypt("add",Session.SessionID);
			Response.Redirect("Default.aspx" + stParam);			
		}
        protected void imgSaveBack_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			SaveRecord();
			Response.Redirect(lblReferrer.Text);
		}
		protected void cmdSaveBack_Click(object sender, System.EventArgs e)
		{
			SaveRecord();
			Response.Redirect(lblReferrer.Text);
		}
        protected void imgCancel_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			Response.Redirect(lblReferrer.Text);
		}
		protected void cmdCancel_Click(object sender, System.EventArgs e)
		{
			Response.Redirect(lblReferrer.Text);
		}

		#endregion

		#region Private Methods

		private void LoadOptions()
		{
            cboContactGroupCategory.Items.Clear();
            foreach (string strEnum in Enum.GetNames(typeof(Data.ContactGroupCategory)))
            {
                ContactGroupCategory itemContactGroupCategory = (ContactGroupCategory)Enum.Parse(typeof(ContactGroupCategory), strEnum);
                cboContactGroupCategory.Items.Add(new ListItem(strEnum, itemContactGroupCategory.ToString("d")));
            }
		}

		private Int32 SaveRecord()
		{
			ContactGroupDetails clsDetails = new ContactGroupDetails();

			clsDetails.ContactGroupCode = txtContactGroupCode.Text;
			clsDetails.ContactGroupName = txtContactGroupName.Text;
			clsDetails.ContactGroupCategory = (ContactGroupCategory) Enum.Parse(typeof(ContactGroupCategory), cboContactGroupCategory.SelectedItem.Value);
			
			ContactGroups clsContactGroup = new ContactGroups();
			Int32 id = clsContactGroup.Insert(clsDetails);
			clsContactGroup.CommitAndDispose();

			return id;
		}


		#endregion

    }
}
